package com.qf.smsplatform.strategy.service.impl;

import com.qf.smsplatform.common.constants.RabbitMQConstants;
import com.qf.smsplatform.common.constants.StrategyConstants;
import com.qf.smsplatform.common.index.StandardSubmit;
import com.qf.smsplatform.strategy.service.FilterChain;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service(value = "router")
@Slf4j
public class RouterStrategy implements FilterChain {

    @Autowired
    private AmqpAdmin amqpAdmin;

    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Override
    public boolean strategy(StandardSubmit submit) {
        log.info("【路由策略】  路由策略执行啦");

        //1.发送的是submit


        //2.发送的队列是

      String queueName =  RabbitMQConstants.TOPIC_SMS_SEND_LOG  + submit.getClientID();
        //3.创建队列
        Queue queue = QueueBuilder.durable(queueName).build();
        amqpAdmin.declareQueue(queue);


        //4.发送消息
        rabbitTemplate.convertAndSend(queueName,submit);

        log.info("【路由策略】  路由策略消息发送成功啦");

        return true;
    }
}
